<template>
  <div class="app-container">
    <el-input v-model="filterText" placeholder="Filter keyword" style="margin-bottom:30px;" />
    <el-tree
      ref="tree2"
      :data="data2"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />

  </div>
</template>

<script>
export default {
  data () {
    return {
      filterText: '',
      data2: [{
        id: 1,
        label: '原料工序'
      }, {
        id: 2,
        label: '溶出工序'
      }, {
        id: 3,
        label: '沉降工序'
      }, {
        id: 4,
        label: '分解工序'
      }, {
        id: 5,
        label: '蒸发工序',
        children: [{
          id: 5001,
          label: '母液蒸发'
        }, {
          id: 5002,
          label: '母液排盐'
        }]
      }],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  },
  watch: {
    filterText (val) {
      this.$refs.tree2.filter(val)
    }
  },

  methods: {
    filterNode (value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    }
  }
}
</script>
